/*
 * Ant Group
 * Copyright (c) 2004-2024 All Rights Reserved.
 */
package com.alipay.zmdepositdemo.controller;

import com.alipay.api.response.AlipayTradeFastpayRefundQueryResponse;
import com.alipay.zmdepositdemo.model.OpenResponse;
import com.alipay.zmdepositdemo.model.TradeRefundModel;
import com.alipay.zmdepositdemo.service.trade.TradeOrderService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 退款
 *
 * @author zhangjian
 * @version TradeRefundController.java, v 0.1 2024年07月04日 14:27 zhangjian
 */
@Api(tags = "退款")
@ApiSupport(order = 5)
@RestController
@RequestMapping(value = "/trade-order")
public class TradeRefundController {

    @Autowired
    private TradeOrderService tradeOrderService;

    /**
     * 申请退款
     *
     * @see <a href="https://opendocs.alipay.com/open/bfe6632d_alipay.trade.refund?scene=common&pathHash=77a53608">...</a>
     */
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "申请退款接口")
    @GetMapping(value = "/trade-refund")
    OpenResponse<Boolean> tradeRefund(
            @RequestBody TradeRefundModel model) {
        return tradeOrderService.tradeRefund(model);
    }

    /**
     * 查询交易退款
     *
     * @see <a href="https://opendocs.alipay.com/open/4b12ed03_alipay.trade.fastpay.refund.query?scene=common&pathHash=d8cac025">...</a>
     */
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "查询交易退款接口")
    @GetMapping(value = "/query-refund")
    OpenResponse<AlipayTradeFastpayRefundQueryResponse> queryRefund(
            // 退款请求号。 请求退款接口时，传入的退款请求号，如果在退款请求时未传入，则该值为创建交易时的商户订单号。
            @ApiParam(value = "退款请求号", defaultValue = "outRefundRequestNoHZ01RF001") @RequestParam(required = false)
            String outRequestNo,
            @ApiParam(value = "订单支付时传入的商户订单号") @RequestParam(required = false) String outTradeNo,
            @ApiParam(value = "支付宝交易号", defaultValue = "2014112611001004680073956707") @RequestParam(required = false) String tradeNo,
            @ApiParam(value = "商家操作员编号id，由商家自定义", defaultValue = "[\"refund_detail_item_list\"]")
            @RequestParam(required = false) List<String> queryOptions) {
        return tradeOrderService.queryRefund(outRequestNo, outTradeNo, tradeNo, queryOptions);
    }
}